#!/usr/bin/env python
# coding=utf-8
# __author__ = 'Yunchao Ling'

# from bs4 import BeautifulSoup


def getIdentifiers(identifiers):
    result = {}
    primary_id = identifiers.PRIMARY_ID
    if primary_id != None:
        result["PRIMARY_ID"] = getNameAndLabel(primary_id)
    secondary_ids = identifiers.find_all('SECONDARY_ID')
    if len(secondary_ids) > 0:
        result["SECONDARY_ID"] = []
        for secondary_id in secondary_ids:
            result["SECONDARY_ID"].append(getNameAndLabel(secondary_id))
    external_ids = identifiers.find_all('EXTERNAL_ID')
    if len(external_ids) > 0:
        result["EXTERNAL_ID"] = []
        for external_id in external_ids:
            result["EXTERNAL_ID"].append(getNameAndLabel(external_id))
    submitter_ids = identifiers.find_all('SUBMITTER_ID')
    if len(submitter_ids) > 0:
        result["SUBMITTER_ID"] = []
        for submitter_id in submitter_ids:
            result["SUBMITTER_ID"].append(getNameAndLabel(submitter_id))
    uuid_ids = identifiers.find_all('UUID')
    if len(uuid_ids) > 0:
        result["UUID"] = []
        for uuid_id in uuid_ids:
            result["UUID"].append(getNameAndLabel(uuid_id))
    return result


def getNameAndLabel(nameandlabel):
    result = {}
    id = nameandlabel.string
    db = nameandlabel.get('namespace')
    attr = nameandlabel.get('label')
    if id != None:
        result['id'] = id
    if db != None:
        result['db'] = db
    if attr != None:
        result['attr'] = attr
    return result


if __name__ == "__main__":
    # soup = BeautifulSoup(open("D:/data/SRA000001/SRA000001.experiment.xml"), 'lxml-xml')
    # exs = soup.find_all("EXPERIMENT")
    # for ex in exs:
    #     identifiers = ex.IDENTIFIERS
    #     if identifiers != None:
    #         print getIdentifiers(identifiers)
    # a=[1,2]
    # a[0]+=1
    # a[1]+=2
    # print(a)
    path="p300.icb.ac.cn:/mnt/p300/bdp/downloads/smb_share/SRA_runid/DRR/DRR000/DRR000019/DRR000019.sra"
    path2=path.replace("p300.icb.ac.cn:/mnt/p300/bdp/downloads","/bdp-picb/downloads")
    print(path2)